package com.example.library.controller;


import com.example.library.bean.model.Book;
import com.example.library.bean.model.User;
import com.example.library.bean.response.Response;
import com.example.library.service.BorrowOrderService;
import com.example.library.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/borrow")
public class BorrowAPI {

    @Autowired
    private BorrowOrderService borrowOrderService;

    @PostMapping("/add")
    public Response addBorrow(long userId, long bookId) {
        User user = new User();
        user.setUserId(userId);
        Book book = new Book();
        book.setBookId(bookId);
        return borrowOrderService.addBorrow(user,book);
    }

    @PostMapping("/return")
    public Response returnBorrow(long userId, long bookId) {
        return borrowOrderService.returnBorrow(userId,bookId);
    }

    @GetMapping("/getNormal")
    public Response getNormal(long userId) {
        return borrowOrderService.getBorrowBooks(userId, Constant.NORMAL);
    }

    @GetMapping("/getHistory")
    public Response getHistory(long userId) {
        return borrowOrderService.getBorrowBooks(userId, Constant.RETURNED);
    }


}
